#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define N 10
#define MLimit 80
void random(int arr[]) {
	for (int i = 0; i < N; i++)
	{
		arr[i] = rand() % MLimit;
	}
}
//计数排序
void CountSort(int arr[]) {
	int count[MLimit] = { 0 };
	for (int i = 0; i < N; i++)
	{
		count[arr[i]]++;
	}
	int k=0;
	for (int i = 0; i < MLimit; i++)
	{
		for (int j = 0; j < count[i]; j++)
		{
			arr[k] = i;
			k++;
		}
	}
	for (int i = 0; i < N; i++)
	{
		printf("%3d", arr[i]);
	}
	printf("\n");
}
//位图
void BitMapSort(int arr[]) {
	long long bit_map[(MLimit / 64) + 1] = { 0 };
	unsigned int row ;
	unsigned int col ;
	for (int i = 0; i < N; i++)
	{
		row = arr[i] / 64;
		col = arr[i] % 64;
		bit_map[row] = bit_map[row] | ((long long)(1)<< col);
	}
	row = (MLimit / 64) + 1;
	for (int j = 0; j < row; j++)
	{
		for (int k = 0; k < 64; k++)
		{
			if (bit_map[j] & ((long long)(1) << k)) {
				printf("%3d", j * 64 + k);
			}
		}
	}
}

//二分查找
int binarySearch(int arr[],int data) {
	int high = N - 1;
	int low = 0;
	int mid;
	while (low<=high)
	{
		mid = (high + low) / 2;
		if (arr[mid]>data)
		{
			high = mid - 1;
		}
		else if (arr[mid] < data)
		{
			low = mid + 1;
		}
		else {
			return mid;
		}
	}
	return -1;
}

void main() {
	srand(time(NULL));
	int arr[N];
	random(arr);
	for (int i = 0; i < N; i++)
	{
		printf("%3d", arr[i]);
	}
	printf("\n");
	int data;
	CountSort(arr);
	//BitMapSort(arr);
	while (rewind(stdin),scanf("%d",&data))
	{
		int ret = binarySearch(arr, data);
		if (ret == -1)
		{
			printf("����������\n");
		}
		else
		{
			printf("%d���±�Ϊ%d\n", data, ret);
		}
	}
	
}